package tr.edu.metu.is.mega.client.user;

import java.util.List;

import tr.edu.metu.is.mega.client.core.SelectionDialog;
import tr.edu.metu.is.mega.client.resource.MEGAResources;
import tr.edu.metu.is.mega.common.dto.UserDTO;
import tr.edu.metu.is.mega.common.dto.UserRole;

import com.extjs.gxt.ui.client.widget.LayoutContainer;

/**
 * Selection Dialog for {@link UserDTO} records.
 * 
 */
public class UserSelectDialog extends SelectionDialog<UserDTO> {

    private UserSearchWindow userSearchPanel;

    /**
     * Default constructor.
     * 
     * @param multiSelect set true to enable multi selection.
     * @param editEnabled set true to enable edit record.
     */
    public UserSelectDialog(boolean multiSelect, boolean editEnabled) {
        this(multiSelect, editEnabled, null);

    }

    /**
     * Default constructor.
     * 
     * @param multiSelect set true to enable multi selection.
     * @param editEnabled set true to enable edit record.
     * @param userRole set role to display only selected type.
     */
    public UserSelectDialog(boolean multiSelect, boolean editEnabled, UserRole userRole) {
        super(multiSelect, editEnabled, userRole);
        setHeading(MEGAResources.RESOURCEBUNDLE.userSelectTitle());
        setSize(720, 460);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected List<UserDTO> getSelectedItems() {
        return userSearchPanel.getSelectedItems();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void setSelectedItems(List<UserDTO> selectedItems) {
        userSearchPanel.setSelectedItems(selectedItems);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected LayoutContainer getSelectionWidget(Object... parameters) {
        userSearchPanel = new UserSearchWindow(isMultiSelect(), (UserRole) parameters[0]);
        return userSearchPanel;
    }
}
